﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.OracleClient;
using System.Data.OleDb;
using System.Text;
using System.Reflection;

namespace Kenly.DBFramework.Gateway
{
    /// <summary>
    /// Represents a attribute that contains metadata of a column,it can be used to marke a property only.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public sealed class ColumnAttribute : Attribute
    {
        private bool _isIdentity;
        private bool _isPrimaryKey;
        private bool _isForeignKey;
        private Type _referenceType;
        private string _columnName = "";
        private int _size;
        private SqlDbType _sqlDbType = SqlDbType.NVarChar;
        private OracleType _oracleType = OracleType.NVarChar;
        private OleDbType _oleDbType = OleDbType.VarWChar;
        private string _propertyName = "";
        private Type _propertyType;

        /// <summary>
        /// 
        /// </summary>
        public static readonly OracleType DefaultOracleType = OracleType.NVarChar;

        /// <summary>
        /// 
        /// </summary>
        public ColumnAttribute()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnName"></param>
        public ColumnAttribute(string columnName)
        {
            _columnName = columnName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="isIdentity"></param>
        public ColumnAttribute(string columnName, bool isIdentity)
        {
            _columnName = columnName;
            _isIdentity = isIdentity;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="isIdentity"></param>
        /// <param name="isPrimaryKey"></param>
        public ColumnAttribute(string columnName, bool isIdentity, bool isPrimaryKey)
        {
            _columnName = columnName;
            _isIdentity = isIdentity;
            _isPrimaryKey = isPrimaryKey;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="isForeignKey"></param>
        /// <param name="referenceType"></param>
        public ColumnAttribute(string columnName, bool isForeignKey, Type referenceType)
        {
            _columnName = columnName;
            _isForeignKey = isForeignKey;
            _referenceType = referenceType;
        }

        /// <summary>
        /// 
        /// </summary>
        public bool IsIdentity
        {
            get
            {
                return _isIdentity;
            }
            set
            {
                _isIdentity = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool IsPrimaryKey
        {
            get
            {
                return _isPrimaryKey;
            }
            set
            {
                _isPrimaryKey = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool IsForeignKey
        {
            get
            {
                return _isForeignKey;
            }
            set
            {
                _isForeignKey = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Type ReferenceType
        {
            get
            {
                return _referenceType;
            }
            set
            {
                _referenceType = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string ColumnName
        {
            get
            {
                return _columnName;
            }
            set
            {
                _columnName = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public int Size
        {
            get
            {
                return _size;
            }
            set
            {
                _size = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public SqlDbType SqlDbType
        {
            get
            {
                return _sqlDbType;
            }
            set
            {
                _sqlDbType = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public OracleType OracleType
        {
            get
            {
                return _oracleType;
            }
            set
            {
                _oracleType = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public OleDbType OleDbType
        {
            get
            {
                return this._oleDbType;
            }
            set
            {
                this._oleDbType = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string PropertyName
        {
            get
            {
                return _propertyName;
            }
            set
            {
                _propertyName = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Type PropertyType
        {
            get
            {
                return _propertyType;
            }
            set
            {
                _propertyType = value;
            }

        }

    }
}
